package com.canaan.business.controller.pc.bill;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.bill.TrayDetailRecord;
import com.canaan.business.service.bill.ITrayDetailRecordService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 托盘明细纪录Controller
 *
 * @author canaan
 * @date 2025-04-03
 */
@Api(tags = "托盘明细纪录")
@RestController
@RequestMapping("/bill/record")
public class TrayDetailRecordController extends BaseController {
    @Resource
    private ITrayDetailRecordService trayDetailRecordService;

    /**
     * 查询托盘明细纪录列表
     */
    @ApiOperation(value = "查询托盘明细纪录列表")
//    @PreAuthorize("@ss.hasPermi('bill:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrayDetailRecord trayDetailRecord) {
        startPage();
        List<TrayDetailRecord> list = trayDetailRecordService.selectTrayDetailRecordList(trayDetailRecord);
        return getDataTable(list);
    }

    /**
     * 导出托盘明细纪录列表
     */
    @ApiOperation(value = "导出托盘明细纪录列表")
    @PreAuthorize("@ss.hasPermi('bill:record:export')")
    @Log(title = "托盘明细纪录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrayDetailRecord trayDetailRecord) {
        List<TrayDetailRecord> list = trayDetailRecordService.selectTrayDetailRecordList(trayDetailRecord);
        ExcelUtil<TrayDetailRecord> util = new ExcelUtil<TrayDetailRecord>(TrayDetailRecord.class);
        util.exportExcel(response, list, "托盘明细纪录数据");
    }

    /**
     * 获取托盘明细纪录详细信息
     */
    @ApiOperation(value = "获取托盘明细纪录详细信息")
//    @PreAuthorize("@ss.hasPermi('bill:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(trayDetailRecordService.selectTrayDetailRecordById(id));
    }

    /**
     * 获取托盘明细纪录详细信息根据托盘编号
     */
    @ApiOperation(value = "获取托盘明细纪录详细信息")
//    @PreAuthorize("@ss.hasPermi('bill:record:query')")
    @GetMapping(value = "/byNo/{no}")
    public AjaxResult getInfo(@PathVariable("no") String no) {
        return success(trayDetailRecordService.selectTrayDetailRecordByNo(no));
    }

    /**
     * 新增托盘明细纪录
     */
    @ApiOperation(value = "新增托盘明细纪录")
    @PreAuthorize("@ss.hasPermi('bill:record:add')")
    @Log(title = "托盘明细纪录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrayDetailRecord trayDetailRecord) {
        return toAjax(trayDetailRecordService.insertTrayDetailRecord(trayDetailRecord));
    }

    /**
     * 修改托盘明细纪录
     */
    @ApiOperation(value = "修改托盘明细纪录")
    @PreAuthorize("@ss.hasPermi('bill:record:edit')")
    @Log(title = "托盘明细纪录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrayDetailRecord trayDetailRecord) {
        return toAjax(trayDetailRecordService.updateTrayDetailRecord(trayDetailRecord));
    }

    /**
     * 删除托盘明细纪录
     */
    @ApiOperation(value = "删除托盘明细纪录")
//    @PreAuthorize("@ss.hasPermi('bill:record:remove')")
    @Log(title = "托盘明细纪录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trayDetailRecordService.deleteTrayDetailRecordByIds(ids));
    }
}
